package com.notice.service;

import com.notice.dao.UserDao;
import com.notice.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {
    @Autowired
    private UserDao userDao;

    public boolean Add(User u){
        if (userDao.Find(u).size()==0){
            if (userDao.AddUser(u)==1) return true;
        }
        return false;
    }

    public boolean Update(User u){
        if (userDao.Update(u)==1) return true;
        return false;
    }

    public boolean delete(String uid){
        if (userDao.Delete(uid)==1){
            return true;
        }
        return false;
    }

    public List<User> getAll(){
       return userDao.FindAll();
    }

    public int LoginCheck(User u){
        int result = -1;
        List<User> users = userDao.Find(u);
        if (users.size()>0){
            result = users.get(0).getUtype();
        }
       return result;
    }

}
